home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / clib / strcmp.c < prev    next >
Text File  |  1996-10-24  |  2KB  |  67 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: strcmp.c,v 1.2 1996/10/19 16:56:28 aros Exp $
  4.  
  5.     Desc: ANSI C function strcmp()
  6.     Lang: english
  7. */
  8.  
  9. /*****************************************************************************
  10.  
  11.     NAME */
  12.     #include <string.h>
  13.  
  14.     int strcmp (
  15.  
  16. /*  SYNOPSIS */
  17.     const char * str1,
  18.     const char * str2)
  19.  
  20. /*  FUNCTION
  21.     Calculate str1 - str2.
  22.  
  23.     INPUTS
  24.     str1, str2 - Strings to compare
  25.  
  26.     RESULT
  27.     The difference of the strings. The difference is 0, if both are
  28.     equal, < 0 if str1 < str2 and > 0 if str1 > str2. Note that
  29.     it may be greater then 1 or less than -1.
  30.  
  31.     NOTES
  32.     This function is not part of a library and may thus be called
  33.     any time.
  34.  
  35.     EXAMPLE
  36.  
  37.     BUGS
  38.  
  39.     SEE ALSO
  40.  
  41.     INTERNALS
  42.  
  43.     HISTORY
  44.     24-12-95    digulla created
  45.  
  46. ******************************************************************************/
  47. {
  48.     int diff;
  49.  
  50.     /* No need to check *str2 since: a) str1 is equal str2 (both are 0),
  51.     then *str1 will terminate the loop b) str1 and str2 are not equal
  52.     (eg. *str2 is 0), then the diff part will be FALSE. I calculate
  53.     the diff first since a) it's more probable that the first chars
  54.     will be different and b) I don't need to initialize diff then. */
  55.     while (!(diff = *str1 - *str2) && *str1)
  56.     {
  57.     /* advance both strings. I do that here, since doing it in the
  58.         check above would mean to advance the strings once too often */
  59.     str1 ++;
  60.     str2 ++;
  61.     }
  62.  
  63.     /* Now return the difference. */
  64.     return diff;
  65. } /* strcmp */
  66.  
  67.